package com.bee.beeAuth.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bee.beeAuth.entity.SysRole;
import com.bee.beeAuth.service.SysRoleService;
import com.bee.beeModel.result.Result;
import com.bee.beeModel.result.ResultTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("/beeAuth/sys-role")
@Api(value ="角色表",tags = "角色表")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    /**
    * 新增角色表
    * @param sysRole
    * @return
    */
    @ApiOperation(value = "新增角色表", notes = "新增角色表")
    @PostMapping
    public Result save(@RequestBody SysRole sysRole) {
        sysRole.setCreateTime(LocalDateTime.now());
        return ResultTool.success(sysRoleService.save(sysRole));
    }
    /**
    * 修改角色表
    * @param sysRole
    * @return
    */
    @ApiOperation(value = "修改角色表", notes = "修改角色表")
    @PostMapping("/edit")
    public Result edit(@RequestBody SysRole sysRole) {
        sysRole.setUpdateTime(LocalDateTime.now());
        return ResultTool.success(sysRoleService.updateById(sysRole));
    }
    /**
    * 根据id删除角色表
    * @param id
    * @return
    */
    @ApiOperation(value = "通过id删除角色表", notes = "通过id删除角色表")
    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable String id) {
        return ResultTool.success(sysRoleService.removeById(id));
    }
    /**
    * 根据id批量删除角色表
    * @param ids
    * @return
    */
    @ApiOperation(value = "通过id批量删除角色表", notes = "通过id批量删除角色表")
    @PostMapping("/batch")
    public Result removeById(@RequestBody String[] ids) {
    List<String> idsList = Arrays.asList(ids);
        return ResultTool.success(sysRoleService.removeByIds(idsList));
    }
    /**
    * 角色表分页查询
    * @param page
    * @param sysRole
    * @return
    */
    @ApiOperation(value = "角色表分页查询", notes = "角色表分页查询")
    @GetMapping("/page")
    public Result getGenFormConfPage(Page page, SysRole sysRole) {
        return ResultTool.success(sysRoleService.page(page, Wrappers.query(sysRole)));
    }

    /**
    * 根据id查询角色表
    * @param id
    * @return
    */
    @ApiOperation(value = "通过id查询角色表", notes = "通过id查询角色表")
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") String id) {
        return ResultTool.success(sysRoleService.getById(id));
    }
}